package com.xigege.netty.nettyComponent.eventLoopAndEventLoopGroup;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;

import java.util.concurrent.TimeUnit;

/**
 * @author huangxi
 * @class TestEventLoop
 * @description TestEventLoop
 * @create 2022-08-19 17:42
 */
public class TestEventLoop {
    public static void main(String[] args) {
        // 创建事件循环组
        // 处理io事件，普通任务，定时任务
        EventLoopGroup eventLoopGroup = new NioEventLoopGroup(2);
        // 处理普通任务，定时任务
        // EventLoopGroup eventLoopGroup = new DefaultEventLoopGroup(2);

        // 获取下一个事件循环对象
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());

        // 执行普通任务
        eventLoopGroup.next().submit(() -> {
            System.out.println(Thread.currentThread().getName() + "执行任务。。");
        });

        // 执行定时任务
        eventLoopGroup.next().scheduleAtFixedRate(() -> {
            System.out.println(Thread.currentThread().getName() + "执行任务");
        }, 3, 1, TimeUnit.SECONDS);

        System.out.println(Thread.currentThread().getName());
    }

}
